package com.gui.hospital.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gui.hospital.mapper.DoctorMapper;
import com.gui.hospital.model.Doctor;
import com.gui.hospital.service.DoctorService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Author:刘舒佳
 * Date:2024/8/23
 */
@Service
@AllArgsConstructor
public class DoctorServiceImpl extends ServiceImpl<DoctorMapper, Doctor> implements DoctorService {
    private final DoctorMapper doctorMapper;

    /**
     * 根据医生姓名查找医生
     * @param name
     * @return
     */
    @Override
    public List<Doctor> findByName(String name) {
        QueryWrapper<Doctor> doctorQueryWrapper = new QueryWrapper<>();
        doctorQueryWrapper.lambda().like(name!=null&&!"".equals(name),Doctor::getName, name);
        List<Doctor> doctors = doctorMapper.selectList(doctorQueryWrapper);
        return doctors;
    }

    @Override
    public Page<Doctor> pageList(Integer page, Integer size, Doctor doctor) {
        Page<Doctor> doctorPage = new Page<>(page,size);
        QueryWrapper<Doctor> doctorQueryWrapper = new QueryWrapper<>();
        doctorQueryWrapper.lambda().like(doctor.getName()!=null&&!"".equals(doctor.getName()),Doctor::getName, doctor.getName());
        doctorQueryWrapper.lambda().eq(doctor.getHospitalDepartmentId()!=null,Doctor::getHospitalDepartmentId, doctor.getHospitalDepartmentId());
        doctorQueryWrapper.lambda().eq(doctor.getHospitalId()!=null,Doctor::getHospitalId, doctor.getHospitalId());
        doctorQueryWrapper.lambda().like(doctor.getType()!=null&&!"".equals(doctor.getType()),Doctor::getType, doctor.getType());
        Page<Doctor> doctorPage1 = doctorMapper.selectPage(doctorPage, doctorQueryWrapper);
        return doctorPage1;
    }

    @Override
    public List<Doctor> findByHdIdAndDate(Integer hdId, String date) {
        List<Doctor> list=doctorMapper.findByHdIdAndDate(hdId,date);
        return list;
    }


}

